import {Card, Row, Col, List, Typography, Space, Tag, Table} from "antd";
import Base from "@/pages/Province/SubjectsOverview/components/Base";
import {CaretDownFilled, CaretUpFilled, FileWordOutlined} from '@ant-design/icons'
import Pie from '@/pages/Province/SubjectDetail/components/Pie'
import type {ColumnsType} from 'antd/es/table';
import {nanoid} from "@ant-design/pro-components";
import {useEffect, useState} from "react";
import {OverView01} from "@/services/Province/Dashboard";
import SchoolLogo from "../../../../config/logos/SchoolLogo";

interface DataType {
  key: string; // table 唯一
  yr: number; // 年度
  total_fund: number; // 总经费数
  ctr_budg_fund: number; // 中央预算经费
  ctr_receive_fund: number; // 中央实际到账经费
  ctr_expend_fund: number; // 中央实支出经费
  lcl_budg_fund: number; // 地方预算经费
  lcl_receive_fund: number; // 地方实际到账经费
  lcl_expend_fund: number; // 地方实际支出经费
  self_budg_fund: number; // 自筹预算经费
  self_receive_fund: number; // 自筹实际经费
  self_expend_fund: number; // 自筹实际支出经费
  other_budg_fund: number; // 其他预算经费
  other_receive_fund: number; // 其他实际到账经费
  other_expend_fund: number; // 其他实际支出经费
}

const columns: ColumnsType<DataType> = [
  {
    title: '年度',
    dataIndex: 'yr',
    key: 'yr',
  },
  {
    title: '学校',
    dataIndex: 'school',
    key: 'school',
  },
  {
    title: '学科',
    dataIndex: 'subject',
    key: 'subject',
  },
  {
    title: '经费总数(万元)',
    dataIndex: 'total_fund',
    key: 'total_fund',
    sorter: (a, b) => a.total_fund - b.total_fund,
  },
  {
    title: '中央预算经费',
    dataIndex: 'ctr_budg_fund',
    key: 'ctr_budg_fund',
    sorter: (a, b) => a.ctr_budg_fund - b.ctr_budg_fund,
  },
  {
    title: '中央实际到账经费',
    key: 'ctr_receive_fund',
    dataIndex: 'ctr_receive_fund',
    sorter: (a, b) => a.ctr_receive_fund - b.ctr_receive_fund,
  },
  {
    title: '中央实际支出经费',
    key: 'ctr_expend_fund',
    dataIndex: 'ctr_expend_fund',
    sorter: (a, b) => a.ctr_expend_fund - b.ctr_expend_fund,
  },
  {
    title: '地方预算经费',
    dataIndex: 'lcl_budg_fund',
    key: 'lcl_budg_fund',
    sorter: (a, b) => a.lcl_budg_fund - b.lcl_budg_fund,
  },
  {
    title: '地方实际到账经费',
    key: 'lcl_receive_fund',
    dataIndex: 'lcl_receive_fund',
    sorter: (a, b) => a.lcl_receive_fund - b.lcl_receive_fund,
  },
  {
    title: '地方实际支出经费',
    key: 'lcl_expend_fund',
    dataIndex: 'lcl_expend_fund',
    sorter: (a, b) => a.lcl_expend_fund - b.lcl_expend_fund,
  },
  {
    title: '学科自筹预算经费',
    dataIndex: 'self_budg_fund',
    key: 'self_budg_fund',
    sorter: (a, b) => a.self_budg_fund - b.self_budg_fund,
  },
  {
    title: '学科自筹实际到账经费',
    key: 'self_receive_fund',
    dataIndex: 'self_receive_fund',
    sorter: (a, b) => a.self_receive_fund - b.self_receive_fund,
  },
  {
    title: '学科自筹实际支出经费',
    key: 'self_expend_fund',
    dataIndex: 'self_expend_fund',
    sorter: (a, b) => a.self_expend_fund - b.self_expend_fund,
  },
];


export default (props) => {

  // // 评估数据
  // const evaluationData = [
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  //   {
  //     title: '第四轮学科评估',
  //     rank: 'A',
  //     school: '南昌大学',
  //     subject: '软件工程'
  //   },
  // ]
  //
  // // 排名数据
  // const rankData = [
  //   {
  //     title: 'ESI',
  //     rank: 102,
  //     year: 2021,
  //     ave: 100
  //   },
  //   {
  //     title: '武书连',
  //     rank: 102,
  //     year: 2021,
  //     ave: 100
  //   },
  //   {
  //     title: '软科',
  //     rank: 102,
  //     year: 2021,
  //     ave: 102
  //   },
  //   {
  //     title: 'ESI',
  //     rank: 102,
  //     year: 2021,
  //     ave: 120
  //   },
  // ];
  //
  // // 建设经费数据
  // const findData: DataType[] = [
  //   {
  //     "key": nanoid(),
  //     "yr": 2015,
  //     "total_fund": 888,
  //     "ctr_budg_fund": 888,
  //     "ctr_receive_fund": 888,
  //     "ctr_expend_fund": 888,
  //     "lcl_budg_fund": 888,
  //     "lcl_receive_fund": 888,
  //     "lcl_expend_fund": 888,
  //     "self_budg_fund": 888,
  //     "self_receive_fund": 888,
  //     "self_expend_fund": 888,
  //     "other_budg_fund": 888,
  //     "other_receive_fund": 888,
  //     "other_expend_fund": 88
  //   },
  //   {
  //     "key": nanoid(),
  //     "yr": 2015,
  //     "total_fund": 888,
  //     "ctr_budg_fund": 888,
  //     "ctr_receive_fund": 888,
  //     "ctr_expend_fund": 888,
  //     "lcl_budg_fund": 888,
  //     "lcl_receive_fund": 888,
  //     "lcl_expend_fund": 888,
  //     "self_budg_fund": 888,
  //     "self_receive_fund": 888,
  //     "self_expend_fund": 888,
  //     "other_budg_fund": 888,
  //     "other_receive_fund": 888,
  //     "other_expend_fund": 88
  //   },
  //   {
  //     "key": nanoid(),
  //     "yr": 2015,
  //     "total_fund": 888,
  //     "ctr_budg_fund": 888,
  //     "ctr_receive_fund": 888,
  //     "ctr_expend_fund": 888,
  //     "lcl_budg_fund": 888,
  //     "lcl_receive_fund": 888,
  //     "lcl_expend_fund": 888,
  //     "self_budg_fund": 888,
  //     "self_receive_fund": 888,
  //     "self_expend_fund": 888,
  //     "other_budg_fund": 888,
  //     "other_receive_fund": 888,
  //     "other_expend_fund": 88
  //   },
  // ];

  const [evaluationData, setEvaluationData] = useState([])
  const [rankData, setrankData] = useState([])
  const [findData, setfindData] = useState([])
  const [reload, setReload] = useState(false)
  useEffect(() => {
    OverView01().then(res => {
      console.log("@OverView", res)
      if (res.status === 0) {
        setEvaluationData(res.evaluationData)
        // setrankData(res.rankData)
        setfindData(res.findData)
      }
    })
  }, [reload])

  return <Base props={props}>
    <Row gutter={[24, 24]}>
      <Col span={24}>
        <Card title="学科评估情况">
          <List
            grid={{gutter: 16, column: 5}}
            dataSource={evaluationData}
            renderItem={item => (
              <List.Item>
                <Card title={item.title}>
                  <img src={SchoolLogo[item.school]} style={{marginRight: 5, marginBottom: 5, width: 30, height: 30}}/>
                  <span style={{fontSize: 16}}>{item.school}-{item.subject}：<Typography.Text
                    strong>{item.rank}</Typography.Text></span>
                  <br/>
                  <Tag style={{marginTop: 5}} color="blue">下一轮预估({item.evaluation})</Tag>
                </Card>
              </List.Item>
            )}
          />
        </Card>
      </Col>
      {/*<Col span={24}>*/}
      {/*  <Card title="学科影响力情况">*/}
      {/*    <List*/}
      {/*      grid={{gutter: 16, column: 5}}*/}
      {/*      dataSource={rankData}*/}
      {/*      renderItem={item => (*/}
      {/*        <List.Item>*/}
      {/*          <Card title={item.school+'-'+item.subject}>*/}
      {/*            <span style={{fontSize: 16}}>*/}
      {/*              <Space align="center">*/}
      {/*                <Typography.Text>{item.title + '-' + item.year}：</Typography.Text>*/}
      {/*              <Typography.Text strong>{item.rank}</Typography.Text>*/}
      {/*                {item.ave - item.rank > 0 && <Tag color="red"><CaretUpFilled />较平均值{item.ave}高{item.ave-item.rank}位</Tag>}*/}
      {/*                {item.ave - item.rank == 0 && <Tag color="blue">与平均值持平</Tag>}*/}
      {/*                {item.ave - item.rank < 0 && <Tag color="green"><CaretDownFilled/>较平均值{item.ave}低{item.rank-item.ave}位</Tag>}*/}
      {/*              </Space>*/}
      {/*            </span>*/}
      {/*          </Card>*/}
      {/*        </List.Item>*/}
      {/*      )}*/}
      {/*    />*/}
      {/*    <Typography.Text strong>*/}
      {/*      注：平均值为本平台已填报学科统计出的均值。*/}
      {/*    </Typography.Text>*/}
      {/*  </Card>*/}
      {/*</Col>*/}
      <Col span={24}>
        <Card title="本学科建设经费数">
          <Row gutter={[24, 24]}>
            <Col span={24}>
              <Table pagination={{pageSize: 10}} columns={columns} dataSource={findData}/>
            </Col>
          </Row>
          {/*<Row gutter={24}>*/}
          {/*  <Col span={8}>*/}
          {/*    <Pie name="预算经费占比(万元)"*/}
          {/*         data={[{value: 100, name: "中央预算经费"}, {value: 200, name: "地方预算经费"}, {value: 100, name: "自筹预算经费"}]}*/}
          {/*         radius="65%"*/}
          {/*         width="100%"*/}
          {/*    />*/}
          {/*  </Col>*/}
          {/*  <Col span={8}>*/}
          {/*    <Pie name="实际到账占比(万元)"*/}
          {/*         data={[{value: 100, name: "中央预算经费"}, {value: 200, name: "地方预算经费"}, {value: 100, name: "自筹预算经费"}]}*/}
          {/*         radius="65%"*/}
          {/*         width="100%"*/}
          {/*         height=""*/}
          {/*    />*/}
          {/*  </Col>*/}
          {/*  <Col span={8}>*/}
          {/*    <Pie name="实际支出占比(万元)"*/}
          {/*         data={[{value: 100, name: "中央预算经费"}, {value: 200, name: "地方预算经费"}, {value: 100, name: "自筹预算经费"}]}*/}
          {/*         radius="65%"*/}
          {/*         width="100%"*/}
          {/*         height=""*/}
          {/*    />*/}
          {/*  </Col>*/}
          {/*</Row>*/}
        </Card>
      </Col>
    </Row>
  </Base>
}
